//
// Created by lewis on 2023/12/20.
//

#include <iostream>
#include <zmq.hpp>
#include <cstring>
#include <iostream>
#include <map>
#include <regex>
class XMLBuilder {
public:
    XMLBuilder(const std::string& rootName) : m_output("<" + rootName + ">\n") {}

    void addWaypoint(const std::string& x, const std::string& y, const std::string& z, const std::string& id) {
        m_output += "\t<waypoints flag=\"1\" id=\"" + id + "\">\n";
        m_output += "\t\t<waypoint>\n";
        m_output += "\t\t\t<waypoint_x>" + x + "</waypoint_x>\n";
        m_output += "\t\t\t<waypoint_y>" + y + "</waypoint_y>\n";
        m_output += "\t\t\t<waypoint_z>" + z + "</waypoint_z>\n";
        m_output += "\t\t</waypoint>\n";
        m_output += "\t</waypoints>\n";
    }

    std::string getXMLString() const {
        return m_output + "</root>";
    }

private:
    std::string m_output;
};

int main()
{
    std::cout << "hello, move car" << std::endl;
    XMLBuilder xmlBuilder("root");

    // 添加车的路径 , x,y,z,id
    xmlBuilder.addWaypoint("325634000", "1167250000", "0", "1");
    xmlBuilder.addWaypoint("325639000", "1167250000", "0", "1");
    xmlBuilder.addWaypoint("325639000", "1167255000", "0", "1");
    xmlBuilder.addWaypoint("325634000", "1167255000", "0", "1");

    std::string move_car_cmd = xmlBuilder.getXMLString();
    zmq::context_t context;
    zmq::socket_t socket(context, ZMQ_PUSH);
    socket.bind("tcp://*:15557");

    zmq::message_t message(move_car_cmd.size());
    memcpy(message.data(), move_car_cmd.c_str(), move_car_cmd.size());
    socket.send(message, zmq::send_flags::none);
    
    return 0;
}

